// observer [观察者模式]
class StateTracker {
    constructor() {
        this.observers = [];
        this.internalState = 10;
    }

// 改变内部状态，触发状态的观察者列表
    change(val) {
        this.internalState = val;
        this.observers.forEach(observer => observer(val));
    }

    // 注册观察者
    registerObserver(ObserverFn) {
        console.log(ObserverFn, '000')
        this.obserers.push(ObserverFn)
    }
}

let p = new StateTracker()
console.log('-------------------------')
console.log(p)
p.change(123)
console.log('-------------------------')
console.log(p)
const fun = () => {
    console.log('222')
}
// p.registerObserver(fun())
